import requests
import time
import json
import os

# 存放壁纸文件夹
if not os.path.exists('215x120'):
    os.mkdir('215x120')
if not os.path.exists('1024x768'):
    os.mkdir('1024x768')
if not os.path.exists('1280x720'):
    os.mkdir('1280x720')
if not os.path.exists('1280x1024'):
    os.mkdir('1280x1024')
if not os.path.exists('1440x900'):
    os.mkdir('1440x900')
if not os.path.exists('1920x1080'):
    os.mkdir('1920x1080')
if not os.path.exists('1920x1200'):
    os.mkdir('1920x1200')
if not os.path.exists('1920x1440'):
    os.mkdir('1920x1440')


try:
    for pages in range(30):
        jsonurl = 'https://apps.game.qq.com/cgi-bin/ams/module/ishow/V1.0/query/workList_inc.cgi?activityId=2735&sVerifyCode=ABCD&sDataType=JSON&iListNum=20&totalpage=0&page=' + str(pages) + '&iOrder=0&iSortNumClose=1&iAMSActivityId=51991&_everyRead=true&iTypeId=2&iFlowId=267733&iActId=2735&iModuleId=2735&_=1578643950203'

        # 获取json文件
        jsonr = json.loads(requests.utils.unquote(requests.get(jsonurl).text))

        # 解析json文件
        for i in jsonr["List"]:
            img1url = i["sProdImgNo_1"][:len(i["sProdImgNo_1"]) -3] + '0'
            img2url = i["sProdImgNo_2"][:len(i["sProdImgNo_2"]) -3] + '0'
            img3url = i["sProdImgNo_3"][:len(i["sProdImgNo_3"]) - 3] + '0'
            img4url = i["sProdImgNo_4"][:len(i["sProdImgNo_4"]) - 3] + '0'
            img5url = i["sProdImgNo_5"][:len(i["sProdImgNo_5"]) - 3] + '0'
            img6url = i["sProdImgNo_6"][:len(i["sProdImgNo_6"]) - 3] + '0'
            img7url = i["sProdImgNo_7"][:len(i["sProdImgNo_7"]) - 3] + '0'
            img8url = i["sProdImgNo_8"][:len(i["sProdImgNo_8"]) - 3] + '0'


            img = requests.get(img1url)
            # 写入本地
            with open('.\\215x120\\' + i["sProdName"] + '.jpg','wb') as f:
                f.write(img.content)

            img = requests.get(img2url)
            with open('.\\1024x768\\' + i["sProdName"] + '.jpg', 'wb') as f:
                f.write(img.content)

            img = requests.get(img3url)
            with open('.\\1280x720\\' + i["sProdName"] + '.jpg','wb') as f:
                f.write(img.content)

            img = requests.get(img4url)
            with open('.\\1280x1024\\' + i["sProdName"] + '.jpg', 'wb') as f:
                f.write(img.content)

            img = requests.get(img5url)
            with open('.\\1440x900\\' + i["sProdName"] + '.jpg', 'wb') as f:
                f.write(img.content)

            img = requests.get(img6url)
            with open('.\\1920x1080\\' + i["sProdName"] + '.jpg', 'wb') as f:
                f.write(img.content)

            img = requests.get(img7url)
            with open('.\\1920x1200\\' + i["sProdName"] + '.jpg', 'wb') as f:
                f.write(img.content)

            img = requests.get(img8url)
            with open('.\\1920x1440\\' + i["sProdName"] + '.jpg', 'wb') as f:
                f.write(img.content)

            print(i["sProdName"] + '.jpg 已下好')
except:pass